package com.cby.olive.sample

import android.os.Bundle
import android.widget.CompoundButton
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import com.cby.android.olive.ext.binding
import com.cby.android.olive.licon.bean.SwitchIconTask
import com.cby.android.olive.licon.manager.LauncherIconManager
import com.cby.android.olive.storage.OlivePreferences
import com.cby.olive.sample.databinding.ActivitySettingsBinding
import com.cby.olive.sample.dialog.DatePickerListener
import com.cby.olive.sample.dialog.DateSelectDialog
import com.cby.olive.sample.dialog.TimePickerListener
import com.cby.olive.sample.dialog.TimeSelectDialog
import java.text.SimpleDateFormat

/**
 * Description:SettingsActivity
 *
 * @author chenbaoyang
 * @create 2023/6/10 14:17
 */
class SettingsActivity : AppCompatActivity() {
    private val binding by binding<ActivitySettingsBinding>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //setContentView(R.layout.activity_settings)
        binding.cbSettingGrayOpen.isChecked = OlivePreferences.getGrayStatus()
        binding.cbSettingGrayOpen.setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
            OlivePreferences.putGrayStatus(isChecked)
        })

        binding.btnSettingDateSelect.setOnClickListener {
            val dialog = DateSelectDialog()
            dialog.listener = object : DatePickerListener{
                override fun onDate(date: String) {
                    println("chenby1111 == date = $date")
                    binding.tvSettingDate.text = date
                }

            }
            dialog.show(supportFragmentManager,"DateSelectDialog")
        }
        binding.btnSettingTimeSelect.setOnClickListener {
            val dialog = TimeSelectDialog()
            dialog.listener = object : TimePickerListener{
                override fun onTime(time: String) {
                    println("chenby1111 == time = $time")
                    binding.tvSettingTime.text = time
                }

            }
            dialog.show(supportFragmentManager,"DateSelectDialog")
        }

        val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")

        LauncherIconManager.addNewTask(
            SwitchIconTask(
                SplashActivity::class.java.name,
                "$packageName.SplashAliasActivity",
                format.parse("2023-07-03 10:00:00").time,
                format.parse("2023-07-05 09:00:00").time
            ),
            SwitchIconTask(
                SplashActivity::class.java.name,
                "$packageName.SplashAlias2Activity",
                format.parse("2023-07-05 10:00:00").time,
                format.parse("2023-07-16 10:00:00").time
            )
        )
    }
}